package com.sywb.chuangyebao.view;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.contract.UserHistoryContract;
import com.sywb.chuangyebao.view.dialog.AlertDialog;

import org.bining.footstone.log.Logger;
import org.bining.footstone.widget.PullToRefreshView;

import butterknife.BindView;

/**
 * 阅读历史
 * Created by duxl on 2018/5/4.
 */

public class UserHistoryActivity extends ActionbarActivity<UserHistoryContract.Presenter> implements UserHistoryContract.View {

    @BindView(R.id.common_recycler)
    RecyclerView commonRecycler;
    @BindView(R.id.common_refresh)
    PullToRefreshView commonRefresh;
    @BindView(R.id.common_nodata_content)
    TextView commonNodataContent;
    @BindView(R.id.common_nodata_icon)
    ImageView commonNodataIcon;
    @BindView(R.id.common_nodata_subtitle)
    TextView commonNodataSubtitle;
    @BindView(R.id.common_nodata)
    RelativeLayout commonNodata;

    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.layout_recycler_refresh;
    }

    @Override
    public void initView(Bundle bundle) {
        super.initView(bundle);
        setTitle(R.string.read_history);
        addMenuImageItme(R.drawable.delete_com, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String msg = getString(R.string.clear_history_hint);
                AlertDialog alertDialog = AlertDialog.newInstance(null, msg, null, null, false);
                alertDialog.setClickListener(new AlertDialog.OnClickListener() {
                    @Override
                    public void onClick(int position) {
                        if (position == 1) {
                            mPresenter.clearHistory();
                        }
                    }
                });
                alertDialog.show(getMyFragmentManager(), "UserHistoryActivity.showConfirmDialog");
            }
        });
        hideMenu(false);
    }

    @Override
    public void initPresenter() {
        mPresenter.initPresenter(this);
    }


    /**
     * 横竖屏切换
     *
     * @param newConfig
     */
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mPresenter.onConfigurationChanged(newConfig);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 10000 && mPresenter != null && data != null) {
            mPresenter.onActivityResult(requestCode, resultCode, data);
        }
    }

    @Override
    public PullToRefreshView getPullToRefreshView() {
        return commonRefresh;
    }

    @Override
    public RecyclerView getRecyclerView() {
        return commonRecycler;
    }

    @Override
    public void setNoData(boolean isNoData) {
        commonNodata.setVisibility(isNoData ? View.VISIBLE : View.GONE);
    }

    @Override
    public void hideMenu(boolean visible) {
        hasMenu(visible);
    }

    @Override
    public boolean getVisibleToTab() {
        return true;
    }

    @Override
    public boolean getVisibleToUser() {
        return true;
    }
}
